package org.jeecg.modules.demo.machineShop.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.demo.machineShop.entity.*;
import org.jeecg.modules.demo.machineShop.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;


/**
 * 首页数据接口
 */

@Api(tags="首页数据接口")
@RestController
@RequestMapping("/machineShop/index")
@Slf4j
public class IndexDataController extends JeecgController<Device, IDeviceService> {
   @Autowired
   private IDeviceService deviceService;


   //各类产品销售统计
   @Autowired
   private IViewProSalesNumService viewProSalesNumService;//视图的服务类，用来读取数据


    //产品销售额统计
    @Autowired
    private IViewOrdPriceSumsService iViewOrdPriceSumsService;

    //顾客地区分布统计
    @Autowired
    private IViewOrdProvinceNumsService iViewOrdProvinceNumsService;

    //订单状态统计     查退款率
    @Autowired
    private IViewOrdStatusNumsService iViewOrdStatusNumsService;

    //退款状态
    @Autowired
    private IViewFauSumsService iViewFauSumsService;

    //员工签到统计
    @Autowired
    private IViewSignSumService iViewSignSumService;

    @GetMapping(value = "/get")
    public Result<?> getIndexData(){
        List<ViewProSalesNum> list_psn = viewProSalesNumService.list();
        return Result.OK(list_psn);//返回数据
    }

    @GetMapping(value = "/get1")
    public Result<?> getIndexData1(){
        List<ViewOrdPriceSums> list_vops = iViewOrdPriceSumsService.list();
        return Result.OK(list_vops);//返回数据
    }

    @GetMapping(value = "/get2")
    public Result<?> getIndexData2(){
        List<ViewOrdProvinceNums> list_vopn = iViewOrdProvinceNumsService.list();
        return Result.OK(list_vopn);//返回数据
    }

    @GetMapping(value = "/get3")
    public Result<?> getIndexData3(){
        List<ViewOrdStatusNums> list_ostatus = iViewOrdStatusNumsService.list();
        return Result.OK(list_ostatus);//返回数据
    }

    @GetMapping(value = "/get4")
    public Result<?> getIndexData4(){
        List<ViewFauSums> list_fausum = iViewFauSumsService.list();
        return Result.OK(list_fausum);//返回数据
    }

    @GetMapping(value = "/get5")
    public Result<?> getIndexData5(){
        List<ViewSignSum> list_signsum = iViewSignSumService.list();
        return Result.OK(list_signsum);//返回数据
    }

    /**
     *
     * @param device
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
   @AutoLog(value = "设备表-分页列表查询")
   @ApiOperation(value="设备表-分页列表查询", notes="设备表-分页列表查询")
   @GetMapping(value = "/list")
   public Result<?> queryPageList(Device device,
                                  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                  HttpServletRequest req) {
       QueryWrapper<Device> queryWrapper = QueryGenerator.initQueryWrapper(device, req.getParameterMap());
       Page<Device> page = new Page<Device>(pageNo, pageSize);
       IPage<Device> pageList = deviceService.page(page, queryWrapper);
       return Result.OK(pageList);
   }
}
